<template>
	<view class="container">
		<view class="pageHeader">
			提现
			<a class="generalBack" @click="backpage()" hover-class="none">
				<image src="/static/b-1.png" style="width: 18upx;height: 30upx;"></image>
			</a>
			<text class="record" @click="record()">记录</text>
		</view>
		<view class="regoodbox">
			<view class="czfs flex">
				<text>到账账户</text>
				<view style="margin-left: 60upx;flex:1">
					<view style="display: flex;align-items: center;justify-content: space-between;">
						<view style="display: flex;align-items: center;position: relative;flex:1">
							<image src="../../static/r-1.png" style="width: 34upx;height: 34upx;margin-right: 12upx;"></image>
							<text>微信</text>
							<view style="position:absolute;top:50upx;left: 40upx;font-size: 26upx;">2小时内到账</view>
						</view>
						<image src="../../static/f-1.png" style="width: 10upx;height: 20upx;"></image>
					</view>
				</view>
			</view>
			<view style="margin-top: 30upx;padding: 0 70upx;">
				<text style="font-size: 30upx;">提现金额</text>
				<view class="flex aic" style="border-bottom: 2upx solid #EFEFEF;margin-top: 20upx;padding:20upx 0 ;">
					<text style="font-size: 42upx;font-weight: 600;margin-right: 16upx;color: #333;">￥</text>
					<input type="number" placeholder="请填入金额" style="font-size: 30upx;flex:1" v-model="widthdrawNum"/>
				</view>
				<view class="flex aic" style="border-bottom: 2upx solid #EFEFEF;margin-top: 20upx;padding:20upx 0 20upx 60upx;">
					<input type="password" placeholder="请输入安全密码" style="font-size: 30upx;flex:1" v-model="safenum"/>
					<!-- <button class="code">发送验证码</button> -->
				</view>
				<button class="rebtn" @click="balaceWithdraw">提现</button>
				<view style="margin-top: 60upx;font-size: 26upx;color: #666;"> <!-- 提现通道关闭 -->
					<view class="pstxt">备注</view>
					<view class="pstxt">提现手续费 : {{beizhu.common_payment_fee}}%</view>
					<view class="pstxt">提现时间 : {{beizhu.withdrawal_day | timeSelect}} {{beizhu.withdrawal_time}}</view>
					<view class="pstxt">每日最多提现 : {{beizhu.withdrawal_max_cash}}</view>
					<view class="pstxt">单笔提现最大值 : {{beizhu.common_max_cash_withdrawal}}</view>
					<view class="pstxt">单笔提现最小值 : {{beizhu.common_minimum_withdrawal}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import postAjax from '../../API/postAjax.js'
	export default {
		data() {
			return {
				userToken: '', // token	
				chargeMethod: 1, //提现方式 默认为 1
				beizhu: {} ,// 备注信息
				widthdrawNum:'',//提现数量
				safenum:''//安全密码
				
			}
		},
		onLoad(options) {
			let that = this
			that.userToken = uni.getStorageSync('token')
			that.get_beizhu()
		},
		filters:{
			timeSelect: function(str) {
				  let  newStr = ''
				  if(str=="1,2,3,4,5,6,7"){
					  newStr = '周一~周日'
				  }else{
					  let newArr = str.split(',')
					  newArr.forEach(item=>{
							if(item==1){
								newStr +='周一'
							}else if(item==2){
								newStr +='周二'
							}else if(item==3){
								newStr +='周三'
							}else if(item==4){
								newStr +='周四'
							}else if(item==5){
								newStr +='周五'
							}else if(item==6){
								newStr +='周六'
							}else if(item==7){
								newStr +='周日'
							}
					  })
				  }
				  return newStr
			}
		},
		methods: {
			// 返回上一页
			backpage() {
				uni.navigateBack({
					delta: 1
				})
			},
			record(){
				uni.navigateTo({
					url:"record?type=2",
					animationDuration:300
				})
			},
			recharge() {
				uni.navigateTo({
					url: 'recharge'
				})
			},

			get_beizhu() {
				let that = this
				postAjax('Cash/withdrawBeizhu', {
				}, function(data) {
					that.beizhu = data.data
				})
			},
			balaceWithdraw(){
				let that = this 
				if(that.widthdrawNum*1<=0){
					uni.showToast({	icon:'none',title:"请输入提现数量"})
					return
				}
				if(that.widthdrawNum*1>that.beizhu.common_max_cash_withdrawal*1){
					uni.showToast({	icon:'none',title:"单笔提现最多为"+that.beizhu.common_max_cash_withdrawal})
					return
				}
				if(that.widthdrawNum*1<that.beizhu.common_minimum_withdrawal*1){
					uni.showToast({	icon:'none',title:"单笔提现最少为"+that.beizhu.common_minimum_withdrawal})
					return
				}
				if(!that.safenum){
					uni.showToast({	icon:'none',title:"请输入安全密码"})
					return
				}
				
				//获取用户openid

				uni.login({
					provider: 'weixin',
					success: function (loginRes) {							  
						uni.getUserInfo({
							provider: 'weixin',
							success: function (infoRes) {
								//infoRes里面有用户信息需要的话可以取一下
							
								let openId=infoRes.userInfo.openId;
							
								
								let formdata={
									token:	that.userToken,						
									nickname:infoRes.userInfo.nickName,
									cash_type:1,
									unionid:infoRes.userInfo.openId,
									openid:infoRes.userInfo.openId,
									avatarurl:infoRes.userInfo.avatarUrl,
									price:that.widthdrawNum,
									paypwd:that.safenum,									
								};
								
								// console.log(formdata)	
																	
								postAjax('Cash/withdraw',formdata,function(data){
									console.log(data)	
									uni.showToast({	icon:'none',title:data.msg})
									if(data.code==0){
										setTimeout(function(){
											uni.navigateTo({
												url:'balance'
											})
										}, 2000);
									}
									
									
								})
								
							},				 
						})

						
					},
				})

				
			}
		}
	}
</script>

<style>
	.generalBack {
		position: absolute;
		top: 40upx;
		left: 30upx;
		display: block;
	}

	.pstxt {
		position: relative;
	}
	.record{
		position: absolute;
		right: 20upx;
		font-size: 28upx;
		padding: 0 20upx;
	}
	.pstxt::before {
		content: '';
		display: block;
		width: 14upx;
		height: 14upx;
		background-color: #999;
		position: absolute;
		left: -24upx;
		top: 10upx;
		border-radius: 50%;
	}

	.pageHeader {
		position: relative;
		height: 64px;
		background-color: #1D84E8;
		line-height: 64px;
		text-align: center;
		font-size: 36upx;
		color: #fff;
		padding-top: 20px;
	}

	.czfs {
		padding: 40upx 40upx 100upx;
		font-size: 30upx;
		color: #333;
		display: flex;
		margin: 40upx 30upx;
		background-color: #EFEFEF;
		border-radius: 5px;
	}

	.rebtn {
		color: #fff;
		background: linear-gradient(90deg, rgba(92, 171, 246, 1) 0%, rgba(30, 132, 232, 1) 100%);
		margin: 160upx auto 0;
		display: block;
		font-size: 30upx;
		border-radius: 4upx;
		width: 456upx;
		height: 76upx;
		line-height: 76upx;
	}

	.rebtn::after,
	.code::after {
		border: none;
	}

	.code {
		color: #007AFF;
		font-size: 30upx;
		border: none;
		display: inline-block;
		width: 180upx;
		background-color: #fff;
		padding: 0;
	}
</style>
